package alpha2;


import java.net.URLEncoder;

import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpDelete;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.util.EntityUtils;

public class Result extends Common{

	@SuppressWarnings("deprecation")
	public static void get(String query, Integer skip, Integer limit) throws Exception{
		System.out.println("Start GET /result 查看识别结果 ...");
	        
        CloseableHttpClient httpclient = HttpClients.createDefault();
        HttpGet request = new HttpGet(HOST + "/result" + "?query=" + URLEncoder.encode(query) + "&skip=" + skip + "&limit=" + limit);

        //发起网络请求 获取返回信息
        CloseableHttpResponse response = httpclient.execute(request);
        String responseBody = EntityUtils.toString(response.getEntity());
        
        System.out.println(responseBody);
	}
	
	public static void delete() throws Exception{
		System.out.println("Start DELETE /result 清空所有识别结果 ...");
	        
        CloseableHttpClient httpclient = HttpClients.createDefault();
        HttpDelete request = new HttpDelete(HOST + "/result");

        //发起网络请求
        httpclient.execute(request);
        
	}
	
	public static void delete(Integer handleId) throws Exception{
		System.out.println("Start DELETE /result/{handle_id} 清空单个 Handle 的识别结果 ...");
	        
        CloseableHttpClient httpclient = HttpClients.createDefault();
        HttpDelete request = new HttpDelete(HOST + "/result/" + handleId);

        //发起网络请求
        httpclient.execute(request);
        
	}
}
